package main

import (
	"github.com/lab-online/internal/user/entity"
	"github.com/lab-online/internal/user/infra/model"
	"gorm.io/gorm"
)

type User struct {
	Username string `json:"username"`
	Name     string `json:"name"`
	Password string `json:"password"`
	Role     uint8  `json:"role"`
}

func setupUser(db *gorm.DB, data *Initial) {
	for _, user := range data.User {
		if db.First(&model.User{}, "username = ?", user.Username).RowsAffected == 0 {
			user.Password, _ = entity.HashPassword(user.Password)
			db.Where(&model.User{Username: user.Username}).Create(&user)
		}
	}
}
